package com.jxwifi.cloud.quickcleanserver.presenter;

import android.content.Context;
import android.view.View;

import com.bigkoo.pickerview.TimePickerView;
import com.jxwifi.cloud.quickcleanserver.app.UrlPool;
import com.jxwifi.cloud.quickcleanserver.model.AuzImpl;
import com.jxwifi.cloud.quickcleanserver.okhttp.Params;
import com.jxwifi.cloud.quickcleanserver.view.BrithdayView;

import java.util.Calendar;
import java.util.Date;

public class BrithdayPresenter {

    private AuzImpl mAuzImpl;

    private BrithdayView mBrithdayView;

    public BrithdayPresenter(BrithdayView brithdayView) {
        this.mBrithdayView = brithdayView;
        mAuzImpl = new AuzImpl();
    }

    public void doBirthday() {
        Params params = new Params();
        params.add("birthday", mBrithdayView.getBrithday());
        mAuzImpl.auzpost(UrlPool.POST_UPDATE_PROFILE, params, new AuzImpl.AuzListener() {
            @Override
            public void AuzSuccess(int code, String data) {
                mBrithdayView.BrithdaySuccessMsg(code, data);
            }

            @Override
            public void AuzFailure(int errorCode, String msg) {
                mBrithdayView.BrithdayFailureMsg(errorCode,msg);
            }
        });
    }

    public void doChoice(Context context){
        Calendar calendar1 = Calendar.getInstance();
        calendar1.add(calendar1.YEAR,-18);
        Calendar calendar2 = Calendar.getInstance();
        calendar2.clear();
        TimePickerView pvtime = new TimePickerView.Builder(context, new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                mBrithdayView.onTimeSelect(date, v);
            }
        }).setType(new boolean[]{true, true, true, false, false, false})
                .setCancelText("取消")
                .setSubmitText("确定")
                .setRangDate(calendar2, calendar1)
                .setDate(calendar1)
                .isCenterLabel(false)//是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .build();
        pvtime.show();
    }


}
